package cn.mulanbay.api.system.factory;

import cn.mulanbay.api.system.bean.RemoteMessageSearch;
import cn.mulanbay.api.system.service.RemoteMessageService;
import cn.mulanbay.business.bean.SysMessageBean;
import cn.mulanbay.business.bean.UserMessageBean;
import cn.mulanbay.common.bean.DataGrid;
import cn.mulanbay.common.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

/**
 * 用户服务降级处理
 *
 * @author fenghong
 */
public class RemoteMessageFallbackFactory implements FallbackFactory<RemoteMessageService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteMessageFallbackFactory.class);

    @Override
    public RemoteMessageService create(Throwable throwable) {

        log.error("用户服务调用失败:{}", throwable.getMessage());

        return new RemoteMessageService() {
            @Override
            public R<Boolean> addUserMsg(UserMessageBean umb) {
                return R.fail("添加用户消息信息异常:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> addSysMsg(SysMessageBean smb) {
                return R.fail("添加系统消息信息异常:" + throwable.getMessage());
            }

            @Override
            public R<DataGrid> getData(RemoteMessageSearch rms) {
                return R.fail("查询消息异常:" + throwable.getMessage());
            }
        };
    }
}
